package com.goldgov.notice.service.impl;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.goldgov.conference.dao.ConferenceUserDao;
import com.goldgov.conference.service.Conference;
import com.goldgov.conference.service.ConferenceUser;
import com.goldgov.distancelearning.dao.DistancelearningUserDao;
import com.goldgov.distancelearning.service.Distancelearning;
import com.goldgov.distancelearning.service.DistancelearningUser;
import com.goldgov.notice.dao.NoticeDao;
import com.goldgov.notice.dao.NoticeUserDao;
import com.goldgov.notice.service.ConferenceNoticeBean;
import com.goldgov.notice.service.Notice;
import com.goldgov.notice.service.NoticeBean;
import com.goldgov.notice.service.NoticeQuery;
import com.goldgov.notice.service.NoticeService;
import com.goldgov.notice.service.NoticeUser;
import com.goldgov.notice.service.NoticeUserQuery;
import com.goldgov.noticetemplate.dao.NoticeTemplateDao;
import com.goldgov.noticetemplate.service.NoticeParam;
import com.goldgov.noticetemplate.service.NoticeTemplate;
import com.goldgov.notifyrecord.dao.NotifyRecordDao;
import com.goldgov.notifyrecord.service.NotifyParam;
import com.goldgov.notifyrecord.service.NotifyRecord;
import com.goldgov.securityworkbench.dict.bean.dto.DictDto;
import com.goldgov.securityworkbench.dict.bean.dto.DictQuery;
import com.goldgov.securityworkbench.dict.dao.IDictDao;
import com.goldgov.utils.DataUtil;
import com.goldgov.utils.DateUtil;
import com.goldgov.utils.JiguangPush;
import com.goldgov.utils.PropertyUtil;

@Service
public class NoticeServiceImpl implements NoticeService{

	@Autowired
	private NoticeDao noticeDao;
	
	@Autowired
	private ConferenceUserDao conferenceUserDao;
	
	@Autowired
	private NoticeUserDao noticeUserDao;
	
	@Autowired
	private DistancelearningUserDao distancelearningUserDao;
	
	@Autowired
	private NotifyRecordDao notifyRecordDao;
	@Autowired
	private IDictDao dictDao;
	
	@Autowired
	private NoticeTemplateDao noticeTemplateDao;
	
	
	@Override
	public List<Notice> getNoticeList(NoticeQuery query) {
		return noticeDao.getNoticeList(query);
	}

	@Override
	public Notice getNotice(String noticeID) {
		return noticeDao.getNotice(noticeID);
	}
	/**
	 * 根据id查询通知公告
	 * @param noticeID
	 * @return
	 */
	@Override
	public Notice getNoticeById(String noticeID) {
		return noticeDao.getNoticeById(noticeID);
	}
	@Override
	public Boolean addNotice(Notice notice) {
		Boolean fase = false;
		int state = noticeDao.addNotice(notice);
		if (state >= 1) {
			fase = true;
		}
		return fase;
	}

	@Override
	public Boolean updateNotice(Notice notice) {
		//Boolean fase = false;
		int state = noticeDao.updateNotice(notice);
		/*if (state >= 1) {
			fase = true;
		}*/
		return true;
	}

	@Override
	public List<Notice> getNoticeReceivedList(NoticeQuery query) {
		return noticeDao.getNoticeReceivedList(query);
	}
	public Boolean deleteNotice(String[] ids) {
		Boolean fase = false;
		int state = noticeDao.deleteNotice(ids);
		if (state >= 1) {
			fase = true;
		}
		return fase;
	}

	@Override
	public List<Notice> getNoticeListFull(NoticeQuery query) {
		return noticeDao.getNoticeListFull(query);
	}

	@Override
	public List<Notice> getNoticeListFullReceive(NoticeQuery query) {
		return noticeDao.getNoticeListFullReceive(query);
	}

	@Override
	public Boolean sendNotice(Conference conference,Integer type) {
		Date d=new Date();
		Boolean b=false;
		int state=0;
		Notice n=new Notice();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateTime = conference.getConferenceBeginDate();
		int indexOf = dateTime.indexOf(".");
		if (indexOf != -1) {
			dateTime = dateTime.substring(0,indexOf);
		}
		//计算会议时长
		Date beginTime = DateUtil.strToDate(conference.getConferenceBeginDate());
		Date endTime = DateUtil.strToDate(conference.getConferenceEndDate());
		long time = (endTime.getTime()-beginTime.getTime())/1000/60/60;
		long time1 = ((endTime.getTime()-beginTime.getTime())/1000/60) % 60;
		Date conferenceBeginTime = DateUtil.parseDate(dateTime);
		String beginDate = sdf.format(conferenceBeginTime);
		n.setMeetingTime(beginDate);//会议时间
		if (time <= 0) {
			n.setTime(time1+"分钟");//会议时长
		}else {
			StringBuilder sb = new StringBuilder();
			sb.append(time+"小时");
			if (time1 > 0) {
				sb.append(time1+"分钟");
			}
			n.setTime(sb.toString());
		}
		n.setSite(conference.getConferenceSite()==null?"":conference.getConferenceSite());//会议地点
		n.setCompere(conference.getCompere()==null?"":conference.getCompere());//主持人
		n.setSourceType(NoticeQuery.SYSTEM_NOTICE);
		n.setPublishState(2);
		n.setPulishDate(d);
		n.setCreateDate(d);
		n.setReceiptState(NoticeQuery.IS_RECEIPT_YES);
		n.setSourceID(conference.getConferenceID());
		String content="定于"+beginDate+"召开的主题为“"+conference.getConferenceName()+"”的会议，请准时参加。";
		String cancelContent="定于"+beginDate+"召开的主题为“"+conference.getConferenceName()+"”的会议，已取消请知晓!";
		Integer contentType=1;
//		if(conference.getConferenceType().equals("5")) {
//			n.setNoticeType("2");//远程教育类型
//			if(publishState.intValue()==3) {
//				n.setNoticeName(conference.getConferenceName()+"取消通知");
//				contentType=2;
//				n.setReceiptState(NoticeQuery.IS_RECEIPT_NO);
//			}else if(publishState.intValue()==1){
//				n.setNoticeName(conference.getConferenceName());
//			}
//			if(type!=null && type.intValue()==1) {
//				n.setNoticeName(conference.getConferenceName()+"修改通知");
//			}
//		}else {
//			if(conference.getConferenceType().contains("5")) {
//				n.setNoticeType("4");//三会一课和远程教育
//				if(publishState.intValue()==3) {
//					n.setNoticeName(conference.getConferenceName()+"取消通知");
//					contentType=2;
//					n.setReceiptState(NoticeQuery.IS_RECEIPT_NO);
//				}else if(publishState.intValue()==1){
//					n.setNoticeName(conference.getConferenceName());
//				}
//				if(type!=null && type.intValue()==1) {
//					n.setNoticeName(conference.getConferenceName()+"修改通知");
//				}
//				
//			}else {
		n.setNoticeType("1");//三会一课类型
		if(type.intValue()==1){ //新增
			n.setNoticeName(conference.getConferenceName());
		}else if(type.intValue()==2) { //修改
			n.setNoticeName(conference.getConferenceName()+"修改通知");
		}else if(type.intValue()==3) { //取消
			n.setNoticeName(conference.getConferenceName()+"取消通知");
			contentType=2;
			n.setReceiptState(NoticeQuery.IS_RECEIPT_NO);
		}
//			}
//		}
		if(contentType==1) {
			n.setNoticeContent(content);
		}else {
			n.setNoticeContent(cancelContent);
		}
		n.setUserID(conference.getUserID());
		n.setUserName(conference.getUserName());
		n.setActiveState(1);
		n.setLastModifyTime(f.format(d));
		List<ConferenceUser> userlist=conferenceUserDao.getUserList(conference.getConferenceID());
		n.setSendNum(userlist.size());
		state=noticeDao.addNotice(n);
		if(null!=userlist && userlist.size()>0) {
			for(ConferenceUser user:userlist) {
				//推送其他参数
				Map<String, String> map = new HashMap<>();
				map.put("id", conference.getConferenceID());//会议id
				map.put("noticeId", n.getNoticeID());//通知id
				map.put("sourceType", n.getSourceType().toString());
				NoticeUser u=new NoticeUser();
				u.setNoticeID(n.getNoticeID());
				u.setUserID(user.getUserID());
				u.setIsRead(NoticeUserQuery.IS_READ_NO);
				u.setUserName(user.getName());
				String noticeContent = "";
				StringBuilder noticeContentMobile = new StringBuilder();
				//取模板逻辑开始
				//拼模板参数
				List<NoticeParam> noticeParams = new ArrayList<>();
				noticeParams.add(new NoticeParam("${receivedName}", user.getName(), "接收人"));
				noticeParams.add(new NoticeParam("${beginDate}", beginDate, "开始时间"));
				noticeParams.add(new NoticeParam("${mettingName}", conference.getConferenceName(), "主题"));
				noticeParams.add(new NoticeParam("${contact}", conference.getUserName(), "联系人"));
				noticeParams.add(new NoticeParam("${mettingDate}", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(beginTime), "会议具体时间"));
				noticeParams.add(new NoticeParam("${mettingSite}", conference.getConferenceSite()==null?"待定":conference.getConferenceSite(), "会议地点"));
				noticeParams.add(new NoticeParam("${mettingTime}", n.getTime(), "会议时长"));
				noticeParams.add(new NoticeParam("${mettingCompere}", conference.getCompere()==null?"待定":conference.getCompere(), "会议主持人"));
				//拼模板参数end
				if(type.intValue()==1 || type.intValue()==2) {
					//开始拼模板内容取得模板内容
					noticeContent = this.getTemplateCon(noticeParams, DataUtil.TEMPLATE_TYPE_SHYK_ADDORUPDATE);
					if (!PropertyUtil.objectNotEmpty(noticeContent)) {
						noticeContentMobile.append(user.getName());
						noticeContentMobile.append("您好:\n\t定于");
						noticeContentMobile.append(beginDate);
						noticeContentMobile.append("召开的主题为“");
						noticeContentMobile.append(conference.getConferenceName());
						noticeContentMobile.append("”的会议，请准时参加。联系人:");
						noticeContentMobile.append(conference.getUserName());
						noticeContentMobile.append("。\n\t会议时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm").format(beginTime));
						noticeContentMobile.append("\n\t会议地点:");
						noticeContentMobile.append(conference.getConferenceSite()==null?"待定":conference.getConferenceSite());
						noticeContentMobile.append("\n\t会议时长:");
						noticeContentMobile.append(n.getTime());
						noticeContentMobile.append("\n\t主持人:");
						noticeContentMobile.append(conference.getCompere()==null?"待定":conference.getCompere());
					}
					if (!PropertyUtil.objectNotEmpty(noticeContentMobile.toString())) {
						noticeContentMobile.append(noticeContent);
					}
				}
				
				if(type.intValue()==1) {
					u.setNoticeContentMobile(noticeContentMobile.toString());
					map.put("noticeType", DataUtil.SHYK_ADD);
				}else if(type.intValue()==2){
					u.setNoticeContentMobile(noticeContentMobile.toString());
					map.put("noticeType", DataUtil.SHYK_UPDATE);
				}else if(type.intValue()==3)  {
					String cancelNotice = this.getTemplateCon(noticeParams, DataUtil.TEMPLATE_TYPE_SHYK_QX);
					if (!PropertyUtil.objectNotEmpty(cancelNotice)) {
						cancelNotice = user.getName()+"您好:\r\n\t定于"+beginDate+"召开的主题为“"+conference.getConferenceName()+"”的会议，"
								+ "临时取消，具体会议时间将另行通知；请知晓。联系人:"+conference.getUserName();
					}
					u.setNoticeContentMobile(cancelNotice);
					map.put("noticeType", DataUtil.SHYK_QX);
				}
				if (!PropertyUtil.objectNotEmpty(u.getNoticeContentMobile())) {
					u.setNoticeContentMobile(noticeContentMobile.toString());
				}
				noticeUserDao.addNoticeUser(u);
				Map<String, String> params = new HashMap<>();
				params.put("userID", u.getUserID().replace("-", ""));
				params.put("modelName", judgeMettingType(n.getNoticeType()) + n.getNoticeName());
				String contentMobile = u.getNoticeContentMobile();
				if (contentMobile.toString().contains("\\r")) {
					contentMobile = contentMobile.replace("\\r", "");
				}
				if (contentMobile.toString().contains("\\n")) {
					contentMobile = contentMobile.replace("\\n", "");
				}
				if (contentMobile.toString().contains("\\t")) {
					contentMobile = contentMobile.replace("\\t", "");
				}
				params.put("content", contentMobile);
				params.put("mapString", JSONObject.toJSONString(map));
				try {
					JiguangPush.jsoup(params);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		if(state>=1) {
			b=true;
		}
		return b;
	}

	@Override
	public Boolean sendDisNotice(Distancelearning dis,Integer type) {//type==1时，修改通知
		Boolean b=false;
		Date d=new Date();
		int state=0;
		Notice n=new Notice();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateTime = dis.getBeginDate();
		int indexOf = dateTime.indexOf(".");
		if (indexOf != -1) {
			dateTime = dateTime.substring(0,indexOf);
		}
		//计算会议时长
		Date beginTime = DateUtil.strToDate(dis.getBeginDate());
		Date endTime = DateUtil.strToDate(dis.getEndDate());
		long time = (endTime.getTime()-beginTime.getTime())/1000/60/60;
		long time1 = ((endTime.getTime()-beginTime.getTime())/1000/60) % 60;
		Date conferenceBeginTime = DateUtil.parseDate(dateTime);
		String beginDate = sdf.format(conferenceBeginTime);
		n.setMeetingTime(beginDate);//会议时间
		if (time <= 0) {
			n.setTime(time1+"分钟");//会议时长
		}else {
			StringBuilder sb = new StringBuilder();
			sb.append(time+"小时");
			if (time1 > 0) {
				sb.append(time1+"分钟");
			}
			n.setTime(sb.toString());
		}
		n.setSite(dis.getDistancelearningSite()==null?"":dis.getDistancelearningSite());//会议地点
		n.setCompere(dis.getCompere()==null?"":dis.getCompere());//主持人
		n.setSourceType(NoticeQuery.SYSTEM_NOTICE);
		n.setPublishState(2);
		n.setPulishDate(d);
		n.setCreateDate(d);
		n.setReceiptState(NoticeQuery.IS_RECEIPT_YES);
		n.setSourceID(dis.getDistancelearningID());
		String content="定于"+beginDate+"召开的主题为“"+dis.getDistancelearningName()+"”的会议，请准时参加。";
		String cancelContent="定于"+beginDate+"召开的主题为“"+dis.getDistancelearningName()+"”的会议，已取消请知晓!";
		Integer contentType=1;
		n.setNoticeType("2");//远程教育类型
		
		if(type.intValue()==1) {
			n.setNoticeName(dis.getDistancelearningName());
		}else if (type.intValue()==2) {
			n.setNoticeName(dis.getDistancelearningName()+"修改通知");
		}else if (type.intValue()==3) {
			n.setNoticeName(dis.getDistancelearningName()+"取消通知");
			n.setReceiptState(NoticeQuery.IS_RECEIPT_NO);
			contentType=2;
		}
		
		if(contentType.intValue()==1) {
			n.setNoticeContent(content);
		}else {
			n.setNoticeContent(cancelContent);
		}
		n.setUserID(dis.getUserID());
		n.setUserName(dis.getUserName());
		n.setActiveState(1);
		n.setLastModifyTime(f.format(d));
		n.setReceiptState(NoticeQuery.IS_RECEIPT_YES);
		List<DistancelearningUser> userlist=distancelearningUserDao.getUserList(dis.getDistancelearningID());
		n.setSendNum(userlist.size());
		state=noticeDao.addNotice(n);
		if(null!=userlist && userlist.size()>0) {
			for(DistancelearningUser user:userlist) {
				Map<String, String> map = new HashMap<>();
				map.put("id", dis.getDistancelearningID());
				map.put("noticeId", n.getNoticeID());
				map.put("sourceType", n.getSourceType().toString());
				
				NoticeUser u=new NoticeUser();
				u.setNoticeID(n.getNoticeID());
				u.setUserID(user.getUserID());
				u.setUserName(u.getUserName());
				u.setIsRead(NoticeUserQuery.IS_READ_NO);
				String noticeContent = "";
				StringBuilder noticeContentMobile = new StringBuilder();
				//取模板逻辑开始
				//拼模板参数
				List<NoticeParam> noticeParams = new ArrayList<>();
				noticeParams.add(new NoticeParam("${receivedName}", user.getName(), "接收人"));
				noticeParams.add(new NoticeParam("${beginDate}", beginDate, "开始时间"));
				noticeParams.add(new NoticeParam("${mettingName}", dis.getDistancelearningName(), "主题"));
				noticeParams.add(new NoticeParam("${contact}", dis.getUserName(), "联系人"));
				noticeParams.add(new NoticeParam("${mettingDate}", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(beginTime), "会议具体时间"));
				noticeParams.add(new NoticeParam("${mettingSite}", dis.getDistancelearningSite()==null?"待定":dis.getDistancelearningSite(), "会议地点"));
				noticeParams.add(new NoticeParam("${mettingTime}", n.getTime(), "会议时长"));
				noticeParams.add(new NoticeParam("${mettingCompere}", dis.getCompere()==null?"待定":dis.getCompere(), "会议主持人"));
				//拼模板参数end
				if (type.intValue()==1 || type.intValue()==2) {
					//开始拼模板内容取得模板内容
					noticeContent = this.getTemplateCon(noticeParams, DataUtil.TEMPLATE_TYPE_YCJY_ADDORUPDATE);
					if (!PropertyUtil.objectNotEmpty(noticeContent)) {
						noticeContentMobile.append(user.getName());
						noticeContentMobile.append("您好:\n\t定于");
						noticeContentMobile.append(beginDate);
						noticeContentMobile.append("召开的主题为“");
						noticeContentMobile.append(dis.getDistancelearningName());
						noticeContentMobile.append("”的会议，请准时参加。联系人:");
						noticeContentMobile.append(dis.getUserName());
						noticeContentMobile.append("。\n\t会议时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm").format(beginTime));
						noticeContentMobile.append("\n\t会议地点:");
						noticeContentMobile.append(dis.getDistancelearningSite()==null?"待定":dis.getDistancelearningSite());
						noticeContentMobile.append("\n\t会议时长:");
						noticeContentMobile.append(n.getTime());
						noticeContentMobile.append("\n\t主持人:");
						noticeContentMobile.append(dis.getCompere()==null?"待定":dis.getCompere());
					}
					if (!PropertyUtil.objectNotEmpty(noticeContentMobile.toString())) {
						noticeContentMobile.append(noticeContent);
					}
				}
				if(type.intValue()==1){
					u.setNoticeContentMobile(noticeContentMobile.toString());
					map.put("noticeType", DataUtil.YCJY_ADD);
				}else if(type.intValue()==2) {
					u.setNoticeContentMobile(noticeContentMobile.toString());
					map.put("noticeType", DataUtil.YCJY_UPDATE);
				}else if(type.intValue()==3) {
					String cancelNotice = this.getTemplateCon(noticeParams, DataUtil.TEMPLATE_TYPE_YCJY_QX);
					if (!PropertyUtil.objectNotEmpty(cancelNotice)) {
						cancelNotice = user.getName()+"您好:\n\t定于"+beginDate+"召开的主题为“"+dis.getDistancelearningName()+"”的会议，"
								+ "临时取消，具体会议时间将另行通知；请知晓。联系人:"+dis.getUserName();
					}
					u.setNoticeContentMobile(cancelNotice);
					map.put("noticeType", DataUtil.YCJY_QX);
				}
				if (!PropertyUtil.objectNotEmpty(u.getNoticeContentMobile())) {
					u.setNoticeContentMobile(noticeContentMobile.toString());
				}
				noticeUserDao.addNoticeUser(u);
				Map<String, String> params = new HashMap<>();
				params.put("userID", u.getUserID().replace("-", ""));
				params.put("modelName", judgeMettingType(n.getNoticeType()) + n.getNoticeName());
				String contentMobile = u.getNoticeContentMobile();
				if (contentMobile.toString().contains("\\r")) {
					contentMobile = contentMobile.replace("\\r", "");
				}
				if (contentMobile.toString().contains("\\n")) {
					contentMobile = contentMobile.replace("\\n", "");
				}
				if (contentMobile.toString().contains("\\t")) {
					contentMobile = contentMobile.replace("\\t", "");
				}
				params.put("content", contentMobile);
				params.put("mapString", JSONObject.toJSONString(map));
				try {
					JiguangPush.jsoup(params);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		if(state>=1) {
			b=true;
		}
		return b;
	}

	@Override
	public Boolean addStudyWarning(NotifyRecord obj) {
		Date d=new Date();
		boolean b=false;
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Notice n=new Notice();
		n.setUserID(obj.getSenderId());
		n.setUserName(obj.getSenderName());
		n.setActiveState(1);
		n.setLastModifyTime(f.format(d));
		n.setNoticeType("3");
		n.setSourceType(NoticeQuery.SYSTEM_NOTICE);
		n.setPublishState(2);
		n.setPulishDate(d);
		n.setCreateDate(d);
		n.setReceiptState(NoticeQuery.IS_RECEIPT_NO);
		n.setNoticeContent("您当前学习时间未达到考核要求请尽快学习!");
		n.setNoticeName("请尽快开始学习！");
		int state=noticeDao.addNotice(n);
		String[] userIds = new String[]{obj.getReceiverId()};
		if(null!=userIds && userIds.length>0) {
			for(String id:userIds) {
				String userName = notifyRecordDao.getUserName(id);
				NoticeUser u=new NoticeUser();
				u.setNoticeID(n.getNoticeID());
				u.setUserID(id);
				u.setUserName(userName);
				u.setIsRead(NoticeUserQuery.IS_READ_NO);
				
				//取模板逻辑开始
				//拼模板参数
				List<NoticeParam> noticeParams = new ArrayList<>();
				noticeParams.add(new NoticeParam("${receivedName}", userName, "接收人"));
				String noticeContentMobile = this.getTemplateCon(noticeParams, DataUtil.TEMPLATE_TYPE_XXYJ);
				if (!PropertyUtil.objectNotEmpty(noticeContentMobile)) {
					noticeContentMobile = userName+"您好:\r\n\t您当前学习时间未达到考核要求请尽快学习!";
				}
				u.setNoticeContentMobile(noticeContentMobile);
				noticeUserDao.addNoticeUser(u);
				
				Map<String, String> params = new HashMap<>();
				params.put("userID", u.getUserID().replace("-", "")); //接收人
				params.put("modelName",judgeMettingType(n.getNoticeType()) + n.getNoticeName()); //标题
				String noticeContent = u.getNoticeContentMobile();
				if (noticeContent.toString().contains("\\r")) {
					noticeContent = noticeContent.replace("\\r", "");
				}
				if (noticeContent.toString().contains("\\n")) {
					noticeContent = noticeContent.replace("\\n", "");
				}
				if (noticeContent.toString().contains("\\t")) {
					noticeContent = noticeContent.replace("\\t", "");
				}
				params.put("content", noticeContent); //内容
				
				Map<String, String> map = new HashMap<>();  //传递的参数
				map.put("noticeId", n.getNoticeID());
				map.put("id", "");
				map.put("noticeType", DataUtil.XXYJ);
				map.put("sourceType", n.getSourceType().toString());
				
				params.put("mapString", JSONObject.toJSONString(map));
				try {
					JiguangPush.jsoup(params);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		if(state>=1) {
			b=true;
		}
		return b;
	}

	@Override
	public List<DictDto> findDictListByPage(DictQuery arg0) {
		return dictDao.findDictListByPage(arg0);
	}
	
	
	/**
	 * 获取收到的通知公告列表
	 * @param query
	 * @return
	 */
	public List<Notice> findMobileNoticeList(NoticeQuery query){
		return noticeDao.findNoticeListByUserId(query);
	}
	public int getUnreadNum(String receiveUserID) {
		return noticeDao.getUnreadNum(receiveUserID);
	}
	/**
	 * 根据id查询详情
	 * @date 2018年8月28日 下午1:23:35 
	 * @author hanxiangyu
	 * @param noticeID
	 * @return
	 */
	public NoticeBean findNoticeById(String noticeID,String userID) {
		return noticeDao.findNoticeById(noticeID,userID);
	}
	
	

	/**
	 * 获取会议信息
	 * @date 2018年7月3日 下午4:44:33 
	 * @author hanxiangyu
	 * @param conferenceId
	 * @return
	 */
	public ConferenceNoticeBean getConferenceById(String conferenceId) {
		return noticeDao.getConferenceById(conferenceId);
	}
	/**
	 * 获取远程教育
	 * @date 2018年7月3日 下午4:44:33 
	 * @author hanxiangyu
	 * @param conferenceId
	 * @return
	 */
	public ConferenceNoticeBean getDisById(String disId) {
		return noticeDao.getDisById(disId);
	}

	/** 
	 * @Description: 获取模板内容进行参数拼接
	 * @author hanxiangyu
	 * @date 2018年7月3日 下午6:46:35 
	 */
	@Override
	public String getTemplateCon(List<NoticeParam> params,String templateType) {
		String content = "";
		//获取模板根据模板进行发送通知
		List<NoticeTemplate> templateList = noticeTemplateDao.findUseableTemplate(templateType);
		if (PropertyUtil.objectNotEmpty(templateList)) {
			NoticeTemplate template = templateList.get(0);
			if (PropertyUtil.objectNotEmpty(template)) {
				content = template.getTemplateContent();
				if (PropertyUtil.objectNotEmpty(params)) {
					for (NoticeParam param : params) {
						if (content.contains(param.getKey())) {
							content = content.replace(param.getKey(), PropertyUtil.objectNotEmpty(param.getValue()) ? param.getValue() : "");
						}
					}
				}
			}
		}
		return content;
	}
	public String judgeMettingType(String noticeType) {
		DictQuery queryDict=new DictQuery();
		queryDict.setQueryDictCode("d_noticeType");
		queryDict.setPageSize(-1);
		List<DictDto> listDict=dictDao.findDictListByPage(queryDict);
		String str = "【通知】";
		for(DictDto d:listDict) {
			if(d.getDictKey().equals(noticeType)) {
				str = "【" + d.getDictValue() + "】";
				break;
			}else {
				str = "【通知】";
			}
		}
		return str;
	}
}
